package com.bigflexlib.x.Math.range
{


	import com.bigflexlib.utils.BasicTestBase;


	public class RangeSetTest extends BasicTestBase
	{
		
		
		
		public function test_getFirstRangeContainingValue( ):void
		{
		
			var rs:RangeSet = RangeSet.fromSeries( [ 0, 10, 20 ] );		
			
			var r_0_10	:Range = rs.ranges[0] as Range;
			var r_10_20	:Range = rs.ranges[1] as Range;
					
			
			assertEquals( rs.getFirstRangeContainingValue( 0 ) , r_0_10 );
			assertEquals( rs.getFirstRangeContainingValue( 1 ) , r_0_10 );
			
			assertEquals( rs.getFirstRangeContainingValue( 10 ) , r_10_20 );
			assertEquals( rs.getFirstRangeContainingValue( 15 ) , r_10_20 );
				

			assertEquals( rs.getFirstRangeContainingValue( 20 ) , 		null );
			assertEquals( rs.getFirstRangeContainingValue( -1 ) , 		null );
			assertEquals( rs.getFirstRangeContainingValue( 10000 ) , 	null );

		
		}
		
		
		
		public function test_fromSeries( ):void
		{
			
			var rs:RangeSet;
			var range:Range;
			
			rs = RangeSet.fromSeries( [ 0, 10, 20 ] );		
		
				assertEquals( rs.ranges.length, 2 );
		
			range = rs.ranges[ 0 ] as Range;
				assertEquals( range.min , 0 );
				assertEquals( range.max , 10 );
				assertTrue( range.minInclusive );
				assertFalse( range.maxInclusive );
				
			range = rs.ranges[ 1 ] as Range;
				assertEquals( range.min , 10 );
				assertEquals( range.max , 20 );
				assertTrue( range.minInclusive );
				assertFalse( range.maxInclusive );



		
			rs = RangeSet.fromSeries( [ 0, 10, 20 ], RangeSet.INCLUDE_MAX );		
		
				assertEquals( rs.ranges.length, 2 );
		
			range = rs.ranges[ 0 ] as Range;
				assertEquals( range.min , 0 );
				assertEquals( range.max , 10 );
				assertFalse( range.minInclusive );
				assertTrue( range.maxInclusive );
				
			range = rs.ranges[ 1 ] as Range;
				assertEquals( range.min , 10 );
				assertEquals( range.max , 20 );
				assertFalse( range.minInclusive );
				assertTrue( range.maxInclusive );
		
		
			rs = RangeSet.fromSeries( [ 0, 10, 20 ], RangeSet.INCLUDE_NONE );		
		
				assertEquals( rs.ranges.length, 2 );
		
			range = rs.ranges[ 0 ] as Range;
				assertEquals( range.min , 0 );
				assertEquals( range.max , 10 );
				assertFalse( range.minInclusive );
				assertFalse( range.maxInclusive );
				
			range = rs.ranges[ 1 ] as Range;
				assertEquals( range.min , 10 );
				assertEquals( range.max , 20 );
				assertFalse( range.minInclusive );
				assertFalse( range.maxInclusive );
		
		
		}
		
		
		
	}
}